A decoder is a combinational circuit that converts n-bit input into 2ⁿ unique outputs.
It is commonly used for address decoding in memory systems or for enabling specific circuits based on binary input.


Example: 3-to-8 Decoder

Concept


Verilog Implementation

Using case statement:

module Decoder3to8(Din, Dout);
input [2:0] Din;
output reg [7:0] Dout; // Declare as reg and 8-bit wide

always @(*) begin
    case (Din)
        3'd0: Dout = 8'b00000001;
        3'd1: Dout = 8'b00000010;
        3'd2: Dout = 8'b00000100;
        3'd3: Dout = 8'b00001000;
        3'd4: Dout = 8'b00010000;
        3'd5: Dout = 8'b00100000;
        3'd6: Dout = 8'b01000000;
        3'd7: Dout = 8'b10000000;
        default: Dout = 8'b00000000;
    endcase
end

endmodule